/*
 * @Author: lei
 * @Description: 测试
 * @FilePath: /树/tree/test_tree.cc
 */

#include <iostream>

#include "create_tree.cc"
#include "definition.h"
#include "traverse.cc"

// g++ -o test_tree test_tree.cc -std=c++11

void TestTraverse(TreeNode* root) {
  vector<int> ans1, ans2, ans3, ans4;
  // PreorderTraverse1(root, ans1);
  PreorderTraverse2(root, ans1);
  InorderTraversal2(root, ans2);
  // InorderTraversal1(root, ans2);
  // PostorderTraverse1(root, ans3);
  PostorderTraverse2(root, ans3);
  LevelTraverse(root, ans4);
  int len = ans1.size();
  cout << "该树有 " << len << " 个节点" << endl;
  cout << "PreorderTraverse:";
  for (auto& val : ans1) {
    cout << val << " ";
  }
  cout << endl;
  cout << "InorderTraverse:";
  for (auto& val : ans2) {
    cout << val << " ";
  }
  cout << endl;
  cout << "PostorderTraverse:";
  for (auto& val : ans3) {
    cout << val << " ";
  }
  cout << endl;
  cout << "LevelTraverse:";
  for (auto& val : ans4) {
    cout << val << " ";
  }
  cout << endl;
}

int main() {
  vector<int> preorder{4, 1, 3, 2, 6, 5, 7};
  vector<int> inorder{1, 2, 3, 4, 5, 6, 7};
  vector<int> postorder{2, 3, 1, 5, 7, 6, 4};
  vector<int> levelorder{4, 1, 6, 3, 5, 7, 2};
  int len = inorder.size();
  // TreeNode* root =
  //     CreateTreeFromPreIn(inorder, preorder, 0, len - 1, 0, len - 1);

  TreeNode* root =
      CreateTreeFromInPost(inorder, postorder, 0, len - 1, 0, len - 1);

  // TreeNode* root =
  //    CreateTreeFromInLevel(inorder, levelorder, 0, len - 1, 0, len - 1);

  // vector<string> data = {"4", "1", "6", "#", "3", "5", "7", "#", "#", "2"};
  // TreeNode* root = CreateTreeFromVector(data);
  TestTraverse(root);
  return 0;
}